//
//  PayPasswordViewController.m
//  BaseFrame
//
//  Created by 吕金状 on 2017/8/16.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "PayPasswordViewController.h"

@interface PayPasswordViewController ()

Strong UITextField *textField;

@end

//网络
@implementation PayPasswordViewController(NetWorking)

- (void)changePaymentPassword{
    if ([self.textField.text isEqualToString:@""]) {
        ShowMessage(@"请输入支付密码");
    }
    [self showprogressHUD];
    NSDictionary *parameters = @{@"auId":[UserModel sharedInstanced].userId,
                                 @"payPassword":self.textField.text
                                 };
    [[AFAppDotNetAPIClient sharedClient] POST:@"/LaundryMall/Login_Registration/changePaymentPassword.action" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if ([responseObject[@"responseStatus"] isEqualToString:@"0"]) {
            [UserModel sharedInstanced].payThePassword = self.textField.text;
            [self.view makeToast:responseObject[@"msg"] duration:1 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
                [self.navigationController popViewControllerAnimated:YES];
            }];
        }
        [self hiddenProgressHUD];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self showError:error];
        [self hiddenProgressHUD];
    }];
    
    
}

@end

//ui
@implementation PayPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"会员卡支付密码";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonItemClick)];
    [self.view addSubview:self.textField];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - click

- (void)rightBarButtonItemClick{
    [self changePaymentPassword];
}

#pragma mark - init

- (UITextField *)textField{
    if (!_textField) {
        _textField  = [[UITextField alloc]initWithFrame:CGRectMake(10 / WIDTH_5S_SCALE, 10 / WIDTH_5S_SCALE, SCREEN_WIDTH - 20 / WIDTH_5S_SCALE, 30 / WIDTH_5S_SCALE)];
        _textField.font = DEF_FontSize_14;
        _textField.textColor = getColor(textColor);
        _textField.placeholder = @"请输入会员卡支付密码";
        _textField.text = [UserModel sharedInstanced].payThePassword;
        _textField.leftViewMode = UITextFieldViewModeAlways;
        _textField.leftView = ({
            UIImageView *titleImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 10 / WIDTH_5S_SCALE, 14 / WIDTH_5S_SCALE)];
            titleImageView.contentMode = UIViewContentModeScaleAspectFit;
            titleImageView.image = [UIImage imageNamed:@"root_left"];
            titleImageView;
        });
    }
    return _textField;
}


@end
